package solution

/**
 * max sum of the subarray
 * @param arr int整型一维数组 the array
 * @return int整型
*/
func maxsumofSubarray( arr []int ) int {
    // write code here
    arrLen := len(arr)
    if arrLen <= 0 {
        return 0
    }
    result := arr[0]
    current := 0
    for i := 0; i < arrLen; i++ {
        // add every item, then use max(nSum, arr[n]) as result
        current += arr[i]
        if current > result {
            result = current
        }
        if current < 0 {
            current = 0
        }
    }
    return result
}
